﻿<?php
$edit_url	=	"?act=list_tpl";
if ($del_id) {
	acp_check_permission('del_tpl');
	if ($_POST['submit']) {
		$mysql->query("DELETE FROM ".$tb_prefix."tpl WHERE tpl_id = '".$del_id."'");
		echo "Đã sửa xong <meta http-equiv='refresh' content='0;url=".$edit_url."'>";
		exit();
	}
	?><table align=center><form method="post">Bạn có muốn xóa không ??????<br><center><input value="Có" name=submit type=submit class=submit></center></form></table><?
}
if($mode == 'edit') {
acp_check_permission('edit_tpl');
	if(is_numeric($id)) {
		$sql			=	"SELECT * FROM ".$tb_prefix."tpl WHERE tpl_id = $id";
		$query			=	$mysql->query($sql);
		if($mysql->num_rows($query)) {
			$row 		=	$mysql->fetch_array($query);
			$tpl_ID		=	$row['tpl_id'];
			$tpl_FNAME	=	$row['tpl_fname'];
			$tpl_SNAME	=	$row['tpl_sname'];
			$tpl_ORDER	=	$row['tpl_order'];
			$action		=	"?act=tpl&mode=edit&id=$id";
			if(isset($_POST['submit'])) {
				$fname	=	$_POST['fname'];
				$sname	=	$_POST['sname'];
				$order	=	$_POST['order'];
				$mysql->query("UPDATE ".$tb_prefix."tpl SET
					tpl_fname				=  	'".$fname."',
					tpl_sname 				= 	'".$sname."',
					tpl_order				=	'".$order."' WHERE tpl_id = '".$id."'");
				echo "<script language='JavaScript'>{ window.parent.location='?act=tpl&mode=edit&id=$id' }</script>";
			}
		}
	}
	if(!$mysql->num_rows($query)) {
		die("Templates này không có trong data");
	}
include("templates/tpl.html");
}
if($mode == 'add') {
acp_check_permission('add_tpl');
	if(isset($_POST['submit'])) {
		$fname	=	$_POST['fname'];
		$sname	=	$_POST['sname'];
		$order	=	$_POST['order'];
		$action	=	"?act=tpl&mode=add";
		$mysql->query("INSERT INTO ".$tb_prefix."tpl (tpl_fname,tpl_sname,tpl_order) 
					VALUES ('".$fname."','".$sname."','".$order."')");
		echo "<script language='JavaScript'>{ window.parent.location='?act=list_tpl' }</script>";
	}
include("templates/tpl.html");
}
								
?>